package edu.maxflow;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;

import org.apache.hadoop.io.Writable;

public class Edge implements Writable {

	private long fromVertexId;

	private long toVertexId;

	private long flow;

	private long capacity;

	public void readFields(DataInput dataInput) throws IOException {
		fromVertexId = dataInput.readLong();
		toVertexId = dataInput.readLong();
		flow = dataInput.readLong();
		capacity = dataInput.readLong();
	}

	public void write(DataOutput dataOutput) throws IOException {
		dataOutput.writeLong(fromVertexId);
		dataOutput.writeLong(toVertexId);
		dataOutput.writeLong(flow);
		dataOutput.writeLong(capacity);
	}

	@Override
	public String toString() {
		StringBuilder builder = new StringBuilder();
		builder.append("Edge [fromVertexId=");
		builder.append(fromVertexId);
		builder.append(", toVertexId=");
		builder.append(toVertexId);
		builder.append(", flow=");
		builder.append(flow);
		builder.append(", capacity=");
		builder.append(capacity);
		builder.append("]");
		return builder.toString();
	}

	@Override
	public boolean equals(Object obj) {
		if (!(obj instanceof Edge)) {
			return false;
		}

		Edge edge = (Edge) obj;

		return (this.toVertexId == edge.toVertexId && this.fromVertexId == edge.fromVertexId) || (this.toVertexId == edge.fromVertexId && this.fromVertexId == edge.toVertexId);
	}

	public long getFromVertexId() {
		return fromVertexId;
	}

	public void setFromVertexId(long fromVertexId) {
		this.fromVertexId = fromVertexId;
	}

	public long getToVertexId() {
		return toVertexId;
	}

	public void setToVertexId(long toVertexId) {
		this.toVertexId = toVertexId;
	}

	public long getFlow() {
		return flow;
	}

	public void setFlow(long flow) {
		this.flow = flow;
	}

	public long getCapacity() {
		return capacity;
	}

	public void setCapacity(long capacity) {
		this.capacity = capacity;
	}

}
